package com.ch.forum.dao;

import com.ch.forum.model.BuySaleReward;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface BuySaleRewardMapper {

    @Insert("insert into t_buy_sale_reward(date,user_id,num,price,bit_coin_name,type,status,mantissa) " +
            "values(#{date},#{userId},#{num},#{price},#{bitCoinName},#{type},#{status},#{mantissa})")
    int recharge(BuySaleReward buySaleReward);

    @Insert("insert into t_buy_sale_reward(date,user_id,num,price,bit_coin_name,type,status,address,name) " +
            "values(#{date},#{userId},#{num},#{price},#{bitCoinName},#{type},#{status},#{address},#{name})")
    int reflect(BuySaleReward buySaleReward);

    @Insert("insert into t_buy_sale_reward(date,user_id,num,price,bit_coin_name,type,multiple,status) " +
            "values(#{date},#{userId},#{num},#{price},#{bitCoinName},#{type},#{multiple},#{status})")
    int buyIn(BuySaleReward buySaleReward);

    @Select("select id,date,user_id,num,price,multiple,type,bit_coin_name,status from t_buy_sale_reward where id = #{id}")
    Map findById(@Param("id")Long id);

    @Select("SELECT t.*,u.nick_name as userName FROM t_buy_sale_reward t LEFT JOIN t_user u ON u.id = t.user_id WHERE t.type = 1 AND `status` = 0")
    List<Map> findRechargeList();

    @Select("SELECT t.*,u.nick_name FROM t_buy_sale_reward t LEFT JOIN t_user u ON u.id = t.user_id WHERE t.type = 2 AND `status` = 0")
    List<Map> findReflectList();

    @Update("update t_buy_sale_reward set status = 1 where id = #{id}")
    int updateStatus(@Param("id")Long id);

    /**
     * 查找用户买入卖出记录
     * @param id
     * @return
     */
    @Select("SELECT t.id,t.date,t.user_id as userId,t.num,t.price,t.multiple,t.bit_coin_name as bitCoinName,t.mantissa as mantissa,t.type,t.status,t.address,t.name FROM t_buy_sale_reward t WHERE (t.type = 3 OR t.type = 4) AND t.user_id = #{id}")
    List<BuySaleReward> findUserReard(@Param("id")Long id);
}
